import wepy from 'wepy'

export default class  extends wepy.mixin {
  data = {
    address:null,
    orderCart:[]
  }

  methods = {
    //选择地址
    async onChooseAdress(){
      const res = await wepy.chooseAddress().catch(err => err)
      if(res.errMsg !== "chooseAddress:ok") return wepy.baseToast("已取消选择")
      wepy.baseToast("选择地址成功")
      this.address = res;
      this.$apply();
      wepy.setStorageSync("address",this.address)
      console.log(res);
      
    }
  }

  computed = {
    //是否显示添加地址按钮
    showChooseAddress(){
      return this.address === null
    },
    // 计算地址
    addressStr(){
      if(this.address === null) return null
      const {provinceName,cityName,countyName,detailInfo} = this.address;
      return provinceName+cityName+countyName+detailInfo
    }
  }

  onLoad(){
    this.address = wepy.getStorageSync("address") || null;
    //拿到清单的商品列表
    
    const orderCart = wepy.getStorageSync("cart").filter(item => item.isCheck)
    this.orderCart = orderCart;
  }
}